package STUDENT.TRANBANGTUNG.day05_06_2016;

import java.util.Scanner;

public class tamgic {
	public static void main(String[] args) {
		String kt;
		double kt1;
		double dientich;
		double chuvi;
		double chieucao;
		String tinh;
		Scanner sc;
		double canh1 = 0;
		double canh2 = 0;
		double canh3 = 0;

		do {
			System.out.println("nhap chieu dai canh 1!");
			do {

				sc = new Scanner(System.in);
				kt = sc.nextLine();
				if (kt.isEmpty()) {
					System.out.println("vui long nhap gia tri vao!");
				} else if (Double.parseDouble(kt) <= 0) {
					System.out.println("so nhap khong dung!");
				} else {
					canh1 = Double.parseDouble(kt);
				}

			} while (kt.isEmpty() || Double.parseDouble(kt) <= 0);
			//
			System.out.println("nhap chieu dai canh 2!");
			do {

				sc = new Scanner(System.in);
				kt = sc.nextLine();

				if (kt.isEmpty()) {
					System.out.println("vui long nhap gia tri vao!");
				} else if (Double.parseDouble(kt) <= 0) {
					System.out.println("so nhap khong dung!");
				} else {
					canh2 = Double.parseDouble(kt);
				}

			} while (kt.isEmpty() || Double.parseDouble(kt) <= 0);

			//
			System.out.println("nhap chieu dai canh 3!");
			do {

				sc = new Scanner(System.in);
				kt = sc.nextLine();

				if (kt.isEmpty()) {
					System.out.println("vui long nhap gia tri vao!");
				} else if (Double.parseDouble(kt) <= 0) {
					System.out.println("so nhap khong dung!");
				} else {
					canh3 = Double.parseDouble(kt);
				}

			} while (kt.isEmpty() || Double.parseDouble(kt) <= 0);
			if (canh1 + canh2 <= canh3 || canh1 + canh3 <= canh2 || canh3 + canh2 <= canh1) {
				System.out.println("3 canh khong hop le!");
			} else {
				System.out.println("nhap gia tri ban can tinh 'dien tich' hoac 'chu vi'!");
				do {
					sc = new Scanner(System.in);
					kt = sc.nextLine();
					if (kt.isEmpty()) {
						System.out.println("vui long nhap phep toan vao!");
					} else {
						if (kt.equals("dien tich")) {
							chuvi = canh1 + canh2 + canh3;
							Double p = chuvi / 2;
							dientich = (Math.sqrt(p * (p - canh1) * (p - canh2) * (p - canh3)));
							System.out.println("dien tich la: " + dientich);
							return;
						} else if (kt.equals("chu vi")) {
							chuvi = canh1 + canh2 + canh3;
							System.out.println("chu vi bang: " + chuvi);
							return;
						} else {
							System.out.println("phep toan khong hop le!");
						}
					}
				} while (kt.isEmpty() || kt.equals("dien tich") == false || kt.equals("chu vi") == false);
			}
		} while (canh1 + canh2 <= canh3 || canh1 + canh3 <= canh2 || canh3 + canh2 <= canh1);
	}
}
